<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公寓名称" prop="apartmentName">
        <el-input
          v-model="queryParams.apartmentName"
          placeholder="请输入公寓名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国家" prop="country">
        <el-input
          v-model="queryParams.country"
          placeholder="请输入国家"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="州或省一级单位" prop="state">
        <el-input
          v-model="queryParams.state"
          placeholder="请输入州或省一级单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入城市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮政编码" prop="postCode">
        <el-input
          v-model="queryParams.postCode"
          placeholder="请输入邮政编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="详细地址" prop="addressInfo">
        <el-input
          v-model="queryParams.addressInfo"
          placeholder="请输入详细地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="纬度" prop="latitude">
        <el-input
          v-model="queryParams.latitude"
          placeholder="请输入纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经度" prop="longtitude">
        <el-input
          v-model="queryParams.longtitude"
          placeholder="请输入经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设施评分" prop="facilityScore">
        <el-input
          v-model="queryParams.facilityScore"
          placeholder="请输入设施评分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交通评分" prop="trafficScore">
        <el-input
          v-model="queryParams.trafficScore"
          placeholder="请输入交通评分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="安全评分" prop="securityScore">
        <el-input
          v-model="queryParams.securityScore"
          placeholder="请输入安全评分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务评分" prop="serviceScore">
        <el-input
          v-model="queryParams.serviceScore"
          placeholder="请输入服务评分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性价比评分" prop="costPerScore">
        <el-input
          v-model="queryParams.costPerScore"
          placeholder="请输入性价比评分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="综合评分" prop="score">
        <el-input
          v-model="queryParams.score"
          placeholder="请输入综合评分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公寓内房型最低租金" prop="rent">
        <el-input
          v-model="queryParams.rent"
          placeholder="请输入公寓内房型最低租金"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="货币种类" prop="currency">
        <el-input
          v-model="queryParams.currency"
          placeholder="请输入货币种类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收藏次数" prop="collections">
        <el-input
          v-model="queryParams.collections"
          placeholder="请输入收藏次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评论次数" prop="comments">
        <el-input
          v-model="queryParams.comments"
          placeholder="请输入评论次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="大图的url地址" prop="imageUrl">
        <el-input
          v-model="queryParams.imageUrl"
          placeholder="请输入大图的url地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公寓简介" prop="briefDesc">
        <el-input
          v-model="queryParams.briefDesc"
          placeholder="请输入公寓简介"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="需要特别强调的优势项目描述：例如打折等等" prop="extraDesc">
        <el-input
          v-model="queryParams.extraDesc"
          placeholder="请输入需要特别强调的优势项目描述：例如打折等等"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['apartment:tbapartmentmain:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['apartment:tbapartmentmain:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['apartment:tbapartmentmain:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['apartment:tbapartmentmain:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tbapartmentmainList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公寓主键" align="center" prop="id" />
      <el-table-column label="公寓名称" align="center" prop="apartmentName" />
      <el-table-column label="国家" align="center" prop="country" />
      <el-table-column label="州或省一级单位" align="center" prop="state" />
      <el-table-column label="城市" align="center" prop="city" />
      <el-table-column label="邮政编码" align="center" prop="postCode" />
      <el-table-column label="详细地址" align="center" prop="addressInfo" />
      <el-table-column label="纬度" align="center" prop="latitude" />
      <el-table-column label="经度" align="center" prop="longtitude" />
      <el-table-column label="设施评分" align="center" prop="facilityScore" />
      <el-table-column label="交通评分" align="center" prop="trafficScore" />
      <el-table-column label="安全评分" align="center" prop="securityScore" />
      <el-table-column label="服务评分" align="center" prop="serviceScore" />
      <el-table-column label="性价比评分" align="center" prop="costPerScore" />
      <el-table-column label="综合评分" align="center" prop="score" />
      <el-table-column label="公寓内房型最低租金" align="center" prop="rent" />
      <el-table-column label="货币种类" align="center" prop="currency" />
      <el-table-column label="收藏次数" align="center" prop="collections" />
      <el-table-column label="评论次数" align="center" prop="comments" />
      <el-table-column label="大图的url地址" align="center" prop="imageUrl" />
      <el-table-column label="公寓简介" align="center" prop="briefDesc" />
      <el-table-column label="需要特别强调的优势项目描述：例如打折等等" align="center" prop="extraDesc" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['apartment:tbapartmentmain:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['apartment:tbapartmentmain:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改公寓对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公寓名称" prop="apartmentName">
          <el-input v-model="form.apartmentName" placeholder="请输入公寓名称" />
        </el-form-item>
        <el-form-item label="国家" prop="country">
          <el-input v-model="form.country" placeholder="请输入国家" />
        </el-form-item>
        <el-form-item label="州或省一级单位" prop="state">
          <el-input v-model="form.state" placeholder="请输入州或省一级单位" />
        </el-form-item>
        <el-form-item label="城市" prop="city">
          <el-input v-model="form.city" placeholder="请输入城市" />
        </el-form-item>
        <el-form-item label="邮政编码" prop="postCode">
          <el-input v-model="form.postCode" placeholder="请输入邮政编码" />
        </el-form-item>
        <el-form-item label="详细地址" prop="addressInfo">
          <el-input v-model="form.addressInfo" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="经度" prop="longtitude">
          <el-input v-model="form.longtitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="设施评分" prop="facilityScore">
          <el-input v-model="form.facilityScore" placeholder="请输入设施评分" />
        </el-form-item>
        <el-form-item label="交通评分" prop="trafficScore">
          <el-input v-model="form.trafficScore" placeholder="请输入交通评分" />
        </el-form-item>
        <el-form-item label="安全评分" prop="securityScore">
          <el-input v-model="form.securityScore" placeholder="请输入安全评分" />
        </el-form-item>
        <el-form-item label="服务评分" prop="serviceScore">
          <el-input v-model="form.serviceScore" placeholder="请输入服务评分" />
        </el-form-item>
        <el-form-item label="性价比评分" prop="costPerScore">
          <el-input v-model="form.costPerScore" placeholder="请输入性价比评分" />
        </el-form-item>
        <el-form-item label="综合评分" prop="score">
          <el-input v-model="form.score" placeholder="请输入综合评分" />
        </el-form-item>
        <el-form-item label="公寓内房型最低租金" prop="rent">
          <el-input v-model="form.rent" placeholder="请输入公寓内房型最低租金" />
        </el-form-item>
        <el-form-item label="货币种类" prop="currency">
          <el-input v-model="form.currency" placeholder="请输入货币种类" />
        </el-form-item>
        <el-form-item label="收藏次数" prop="collections">
          <el-input v-model="form.collections" placeholder="请输入收藏次数" />
        </el-form-item>
        <el-form-item label="评论次数" prop="comments">
          <el-input v-model="form.comments" placeholder="请输入评论次数" />
        </el-form-item>
        <el-form-item label="大图的url地址" prop="imageUrl">
          <el-input v-model="form.imageUrl" placeholder="请输入大图的url地址" />
        </el-form-item>
        <el-form-item label="公寓简介" prop="briefDesc">
          <el-input v-model="form.briefDesc" placeholder="请输入公寓简介" />
        </el-form-item>
        <el-form-item label="需要特别强调的优势项目描述：例如打折等等" prop="extraDesc">
          <el-input v-model="form.extraDesc" placeholder="请输入需要特别强调的优势项目描述：例如打折等等" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTbapartmentmain, getTbapartmentmain, delTbapartmentmain, addTbapartmentmain, updateTbapartmentmain } from "@/api/apartment/tbapartmentmain";

export default {
  name: "Tbapartmentmain",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公寓表格数据
      tbapartmentmainList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        apartmentName: null,
        country: null,
        state: null,
        city: null,
        postCode: null,
        addressInfo: null,
        latitude: null,
        longtitude: null,
        facilityScore: null,
        trafficScore: null,
        securityScore: null,
        serviceScore: null,
        costPerScore: null,
        score: null,
        rent: null,
        currency: null,
        collections: null,
        comments: null,
        imageUrl: null,
        briefDesc: null,
        extraDesc: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询公寓列表 */
    getList() {
      this.loading = true;
      listTbapartmentmain(this.queryParams).then(response => {
        this.tbapartmentmainList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        apartmentName: null,
        country: null,
        state: null,
        city: null,
        postCode: null,
        addressInfo: null,
        latitude: null,
        longtitude: null,
        facilityScore: null,
        trafficScore: null,
        securityScore: null,
        serviceScore: null,
        costPerScore: null,
        score: null,
        rent: null,
        currency: null,
        collections: null,
        comments: null,
        imageUrl: null,
        briefDesc: null,
        extraDesc: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加公寓";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTbapartmentmain(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改公寓";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTbapartmentmain(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTbapartmentmain(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除公寓编号为"' + ids + '"的数据项？').then(function() {
        return delTbapartmentmain(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('apartment/tbapartmentmain/export', {
        ...this.queryParams
      }, `tbapartmentmain_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
